home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / GNU-SMALLTALK.lha / examples / printHier.st < prev    next >
Text File  |  1992-02-15  |  2KB  |  61 lines

  1. "Print out the class inheritance hierarchy."
  2.  
  3. "======================================================================
  4. |
  5. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  6. | Written by Steve Byrne.
  7. |
  8. | This file is part of GNU Smalltalk.
  9. |
  10. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  11. | under the terms of the GNU General Public License as published by the Free
  12. | Software Foundation; either version 1, or (at your option) any later version.
  13. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  14. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  16. | details.
  17. | You should have received a copy of the GNU General Public License along with
  18. | GNU Smalltalk; see the file LICENSE.  If not, write to the Free Software
  19. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  20. |
  21.  ======================================================================"
  22.  
  23.  
  24.  
  25. !Behavior methodsFor: 'demo'!
  26.  
  27. printHierarchy
  28.     "I my entire subclassclass hierarchy on the terminal."
  29.     self printSubclasses: 0    
  30. !!
  31.  
  32. !Behavior methodsFor: 'private'!
  33.  
  34. printSubclasses: level
  35.     "I print my name, and then all my subclasses, each indented according
  36.      to its position in the hierarchy."
  37.     | mySubclasses |
  38.     self indentToLevel: level.
  39.     self name printNl.
  40.     mySubclasses _ self subclasses asSortedCollection:
  41.                         [ :a :b | (a name isNil or: [ b name isNil ])
  42.                                       ifTrue: [ true ]
  43.                               ifFalse: [ a name <= b name ] ].
  44.     mySubclasses do:
  45.         [ :subclass | subclass class ~~ Metaclass
  46.                     ifTrue: [ subclass printSubclasses: level + 1 ] ]
  47. !
  48.  
  49. indentToLevel: level
  50.     level timesRepeat:
  51.         [ stdout next: (self hierarchyIndent) put: Character space ]
  52. !
  53.  
  54. hierarchyIndent
  55.     ^4
  56. !!
  57.  
  58. Object printHierarchy!
  59.